#include "format.hpp"
#include "sink.hpp"
#include "logger.hpp"


  void test_log()
  {  
    qywlog::Logger::ptr logger = qywlog::LoggerManager::getInstance().getLogger("async_logger");
    logger->debug(__FILE__, __LINE__, "%s", "测试日志");
    logger->info(__FILE__, __LINE__, "%s", "测试日志");
    logger->warn(__FILE__, __LINE__, "%s", "测试日志");
    logger->error(__FILE__, __LINE__, "%s", "测试日志");
    logger->fatal(__FILE__, __LINE__, "%s", "测试日志");
    size_t count = 0;
    std::string str = "测试日志-";
    while(count < 500000)
    {
      logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
    }
  }

int main()
{
  //std::string logger_name = "sync_logger";
  //qywlog::LogLevel::value limit = qywlog::LogLevel::value::WARN;
  //qywlog::Formatter::ptr fmt(new qywlog::Formatter("[%d{%H:%M:%S}][%c][%f:%l][%p]%T%m%n"));
  //qywlog::LogSink::ptr stdout_lsp = qywlog::SinkFactory::create<qywlog::StdoutSink>();
  //qywlog::LogSink::ptr file_lsp = qywlog::SinkFactory::create<qywlog::FileSink>("./logfile/test.log");
  //qywlog::LogSink::ptr roll_lsp = qywlog::SinkFactory::create<qywlog::RollBySizeSink>("./logfile/roll-", 1024*1024);
  //std::vector<qywlog::LogSink::ptr> sinks = {stdout_lsp, file_lsp, roll_lsp};
  //qywlog::Logger::ptr logger(new qywlog::SyncLogger(logger_name, limit, fmt, sinks));

  // 建造者模式  --  各个零件之间无先后顺序
//  std::unique_ptr<qywlog::LoggerBuilder> builder(new qywlog::LocalLoggerBuilder());
//  builder->buildLoggerName("sync_logger");
//  builder->buildLoggerLevel(qywlog::LogLevel::value::WARN);
//  builder->buildFormatter("%m%n");
//  builder->buildLoggerType(qywlog::LoggerType::LOGGER_SYNC);
//  builder->buildSink<qywlog::FileSink>("./logfile/test.log");
//  builder->buildSink<qywlog::StdoutSink>();
//  qywlog::Logger::ptr logger = builder->build();

//  logger->debug(__FILE__, __LINE__, "%s", "测试日志");
//  logger->info(__FILE__, __LINE__, "%s", "测试日志");
//  logger->warn(__FILE__, __LINE__, "%s", "测试日志");
//  logger->error(__FILE__, __LINE__, "%s", "测试日志");
//  logger->fatal(__FILE__, __LINE__, "%s", "测试日志");
//  size_t cursize = 0, count = 0;
//  std::string str = "测试日志-";
//  while(cursize < 1024 * 1024 *10)
//  {
//    logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
//    cursize += 20;
//  }

  // 日志器模块 - 异步缓冲区 + 异步工作器 + 异步日志器 测试 
  // std::unique_ptr<qywlog::LoggerBuilder> builder(new qywlog::LocalLoggerBuilder());
  //builder->buildLoggerName("async_logger");
  //builder->buildLoggerLevel(qywlog::LogLevel::value::WARN);
  //builder->buildFormatter("[%c]%m%n");
  //builder->buildLoggerType(qywlog::LoggerType::LOGGER_ASYNC);
  //builder->buildEnableUnSageAsync();
  //builder->buildSink<qywlog::FileSink>("./logfile/async.log");
  //builder->buildSink<qywlog::StdoutSink>();
  //qywlog::Logger::ptr logger = builder->build();

  //logger->debug(__FILE__, __LINE__, "%s", "测试日志");
  //logger->info(__FILE__, __LINE__, "%s", "测试日志");
  //logger->warn(__FILE__, __LINE__, "%s", "测试日志");
  //logger->error(__FILE__, __LINE__, "%s", "测试日志");
  //logger->fatal(__FILE__, __LINE__, "%s", "测试日志");
  //size_t count = 0;
  //std::string str = "测试日志-";
  //while(count < 500000)
  //{
  //  logger->fatal(__FILE__, __LINE__, "测试日志-%d", count++);
  //}

  // 日志器模块管理器测试 + 全局单例模式下日志器的建造者
  std::unique_ptr<qywlog::LoggerBuilder> builder(new qywlog::GlobalLoggerBuilder());
  builder->buildLoggerName("async_logger");
  builder->buildLoggerLevel(qywlog::LogLevel::value::WARN);
  builder->buildFormatter("[%c]%m%n");
  builder->buildLoggerType(qywlog::LoggerType::LOGGER_ASYNC);
  builder->buildEnableUnSageAsync();
  builder->buildSink<qywlog::FileSink>("./logfile/async.log");
  builder->buildSink<qywlog::StdoutSink>();
  builder->build();
  test_log();

  return 0;
}
